package com.william.jdbcplus.core.condition.criterion;

import java.io.Serializable;

/**
 * Order By 片段
 *
 * @author niliwei
 */
public interface OrderBy<Wrap, R> extends Serializable {

    /**
     * 升序
     *
     * @param column
     * @return
     */
    default Wrap orderByAsc(R column) {
        return orderBy(true, column);
    }

    /**
     * 多字段升序
     *
     * @param columns
     * @return
     */
    default Wrap orderByAsc(R... columns) {
        return orderBy(true, columns);
    }

    /**
     * 降序
     *
     * @param column
     * @return
     */
    default Wrap orderByDesc(R column) {
        return orderBy(false, column);
    }

    /**
     * 排序：ORDER BY 字段, ... DESC
     * <p>例: orderByDesc("id", "name")</p>
     *
     * @param columns 字段数组
     * @return children
     */
    default Wrap orderByDesc(R... columns) {
        return orderBy(false, columns);
    }

    /**
     * 排序：ORDER BY 字段, ...
     * <p>例: orderBy(true, "id", "name")</p>
     *
     * @param isAsc   是否是 ASC 排序
     * @param columns 字段数组
     * @return children
     */
    Wrap orderBy(boolean isAsc, R... columns);

    /**
     * 排序：ORDER BY 字段, ...
     * <p>例: orderBy(true, "id")</p>
     *
     * @param isAsc  是否是 ASC 排序
     * @param column 字段
     * @return children
     */
    Wrap orderBy(boolean isAsc, R column);

    /**
     * 排序
     * <p>
     * 例 orderByCount(true, "id")
     * 等价于 order by count(id) asc
     * </p>
     *
     * @param isAsc
     * @param column
     * @return
     */
    Wrap orderByCount(boolean isAsc, R column);

    /**
     * 排序
     * <p>
     * 例 orderBySum(true, "id")
     * 等价于 order by sum(id) asc
     * </p>
     *
     * @param isAsc
     * @param column
     * @return
     */
    Wrap orderBySum(boolean isAsc, R column);

    /**
     * 排序
     * <p>
     * 例 orderByAvg(true, "id")
     * 等价于 order by avg(id) asc
     * </p>
     *
     * @param isAsc
     * @param column
     * @return
     */
    Wrap orderByAvg(boolean isAsc, R column);

    /**
     * 排序
     * <p>
     * 例 orderByMax(true, "id")
     * 等价于 order by max(id) asc
     * </p>
     *
     * @param isAsc
     * @param column
     * @return
     */
    Wrap orderByMax(boolean isAsc, R column);

    /**
     * 排序
     * <p>
     * 例 orderByMin(true, "id")
     * 等价于 order by min(id) asc
     * </p>
     *
     * @param isAsc
     * @param column
     * @return
     */
    Wrap orderByMin(boolean isAsc, R column);

}
